<!--suppress HtmlUnknownTag -->
<root xmlns="http://www.w3.org/1999/xhtml"
      xmlns:py="http://genshi.edgewall.org/"
      xmlns:xi="http://www.w3.org/2001/XInclude">
  <xi:include href="rds.html"/>

  <?python
      import os
      from base64 import b64encode
      from mnemoply import model
      from mnemoply.utils import MonthYear, getBarcodeImage, read_binary_file
      from mnemoply.common_knowledge import month_captions
  ?>

  <report>
    <pages>
      <?python
          objs = [model.StudentAgreement.get(int(x)) for x in ids]


          def getGroupTitle(agr):
              sig = model.StudentInGroup.selectBy(studentAgreement=agr)
              if sig.count() == 1:
                  return sig[0].group.title
              return ""
      ?>

      <page py:for="agr in objs">
        <agr py:content="agr.id"></agr>
        <student py:content="agr.student.fullName" ></student>
        <customer>${"%s %s %s" % (agr.customer.surname, agr.customer.forename, agr.customer.patronymic)}</customer>
        <phone py:content="agr.customer.phone"></phone>
        <group py:content="getGroupTitle(agr)"></group>
        <?python
            env = model.environment.Environment
            prefix = env.getValue('payment_type_month')
            barcodes_dir = "barcodes"
            barcode_num = prefix + str(agr.id).rjust(6, "0")
            barcode_file = getBarcodeImage(barcode_num, barcodes_dir)

            barcode_b64 = b64encode(read_binary_file("./" + barcode_file))
        ?>
        <barcode_num py:content="'barcode_'+str(barcode_num)"></barcode_num>
        <barcode>
          <filename>${barcode_num}.png</filename>
          <data py:content="barcode_b64"></data>
        </barcode>
      </page>
    </pages>
  </report>

</root>
